# -*- coding:utf-8 -*- #

import simplejson as json

def json2proxy(jsonformat):
    """pack jsonformat and return str using for transport"""
    #msg = json.dumps(jsonformat)
    msg = jsondumps(jsonformat)
    return '%s$%s\n' % (len(msg), msg)


def jsonloads(jsonstr):
    return json.loads(jsonstr)


def jsondumps(jsonformat, ensure_ascii=True):
    return json.dumps(jsonformat, ensure_ascii=ensure_ascii)


def proxy2json(recv):
    """
    recv data from socket and return json format
    recv: socket handle
    """
    #msg = json.loads(recv)

def s2datetime(seconds):
    """seconds to datetime"""
    import time
    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(float(seconds)))
